﻿Public Class FormJNJPB
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Public usr As String
    Dim txt As TextBox
    Dim objMstTechnology As New clsMstTechnology
    Private objJNJPB As New clsJNJPB
    Private update_status As String = "INSERT_TYPE"
    Private en As entityJNJPB
    Private _sys_id As String
    Public Property Sys_id As String
        Get
            Return _sys_id
        End Get
        Set(value As String)
            _sys_id = value
        End Set
    End Property
    Private Sub FormJNJPB_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = GetIniFile("JS", "JS8", "", g_jsInitFileName)
        txtDate.Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True
        txtDate.Properties.VistaEditTime = DevExpress.Utils.DefaultBoolean.True
        initForm()
        If _sys_id <> "" Then
            update_status = "UPDATE_TYPE"
            setContentBySysid()
        Else
            update_status = "INSERT_TYPE"
        End If
    End Sub

    Private Sub initForm()
        Dim jnjs As String = GetIniFile("JNJPB", "JNJ", "", g_jsInitFileName)
        Dim jnjList As String() = jnjs.Split("，")
        cmbJnj.Items.Clear()
        For index = 0 To jnjList.Count() - 1
            cmbJnj.Items.Add(jnjList(index))
        Next
        If cmbJnj.Items.Count > 0 Then
            cmbJnj.SelectedIndex = 0
        End If
        Dim xsjs As String = GetIniFile("JNJPB", "XSJ", "", g_jsInitFileName)
        Dim xsjList As String() = xsjs.Split("，")
        cmbXsj.Items.Clear()
        For index = 0 To xsjList.Count() - 1
            cmbXsj.Items.Add(xsjList(index))
        Next
        If cmbXsj.Items.Count > 0 Then
            cmbXsj.SelectedIndex = 0
        End If
        Dim dtMstTechnology As DataTable = objMstTechnology.getListByName(Me.Text)
        If dtMstTechnology.Rows.Count > 0 Then
            txtId.Text = dtMstTechnology.Rows(0)("sys_id").ToString()
            txtRequirement.Text = dtMstTechnology.Rows(0)("requirement").ToString()
            Dim TDate As String = Now.ToString()
            txtDate.Text = TDate
            txtBatch.Text = String.Empty
            RadioButton1.Checked = True
            RadioButton3.Checked = True
            RadioButton6.Checked = True
            txt_hs_yysg.Value = 0
            txt_hs_yysb.Value = 0
            txt_hs_pb.Value = 0
            txt_nd.Value = 0
        End If
    End Sub

    Private Sub setContentBySysid()
        Dim dt As DataTable = objJNJPB.selectBySysid(_sys_id)
        If dt.Rows.Count > 0 Then
            Dim row As DataRow = dt.Rows(0)
            txtDate.Text = row("oper_date")
            cmbJnj.Text = row("jnj")
            txtBatch.Text = row("batch")
            If row("color") = 1 Then
                RadioButton1.Checked = True
            End If
            If row("color") = 0 Then
                RadioButton2.Checked = True
            End If
            If row("prec_stir") = 1 Then
                RadioButton3.Checked = True
            End If
            If row("prec_stir") = 0 Then
                RadioButton4.Checked = True
            End If
            txt_hs_yysg.Text = row("hs_yysg")
            txt_hs_yysb.Text = row("hs_yysb")
            If row("prec") = 1 Then
                RadioButton5.Checked = True
            End If
            If row("prec") = 0 Then
                RadioButton6.Checked = True
            End If
            cmbXsj.Text = row("xsj")
            txt_nd.Text = row("nd")
            txt_hs_pb.Text = row("hs_pb")
        End If
    End Sub

    Private Sub txt_num_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_nd.MouseDown, txt_hs_yysg.MouseDown, txt_hs_yysb.MouseDown, txt_hs_pb.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub

    Private Sub setEntity()
        en = New entityJNJPB
        With en
            .sys_id = _sys_id
            .factory_id = "TS"
            .technology_id = txtId.Text
            .oper_date = txtDate.Text
            .jnj = cmbJnj.Text
            .batch = txtBatch.Text
            .color = IIf(RadioButton1.Checked = True, "1", "0")
            .prec_stir = IIf(RadioButton3.Checked = True, "1", "0")
            .hs_yysg = txt_hs_yysg.Text
            .hs_yysb = txt_hs_yysb.Text
            .prec = IIf(RadioButton5.Checked = True, "1", "0")
            .xsj = cmbXsj.Text
            .nd = txt_nd.Text
            .hs_pb = txt_hs_pb.Text
            .oper = usr
        End With

    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If String.IsNullOrEmpty(txtBatch.Text.Trim()) Then
            MsgBox("请选择不合格原因", vbYes, "提示")
            Exit Sub
        End If
        If String.IsNullOrEmpty(txtDate.Text.Trim()) Then
            MsgBox("请选择操作日期", vbYes, "提示")
            Exit Sub
        End If
        setEntity()
        If update_status = "INSERT_TYPE" Then
            If objJNJPB.insert(en) <> -2 Then
                MsgBox("保存成功", vbYes, "提示")
                initForm()
            Else
                MsgBox("保存失败", vbYes, "提示")
            End If
        End If
        If update_status = "UPDATE_TYPE" Then
            If objJNJPB.update(en) <> -2 Then
                MsgBox("保存成功", vbYes, "提示")
                CType(Owner, FormJNJPBRecord).setDgvData()
                Close()
            Else
                MsgBox("保存失败", vbYes, "提示")
            End If
        End If
    End Sub

End Class

Public Class entityJNJPB
    Public sys_id As String
    Public factory_id As String
    Public technology_id As String
    Public oper_date As String
    Public jnj As String '胶黏剂
    Public batch As String '批次号
    Public color As String '颜色是否正常
    Public prec_stir As String '沉淀是否搅开
    Public hs_yysg As String '原液手工搅拌耗时
    Public hs_yysb As String '原液设备搅拌耗时
    Public prec As String '是否有沉淀
    Public xsj As String '稀释剂
    Public nd As String '粘度
    Public hs_pb As String '配备耗时
    Public oper As String
End Class